package com.gqyin.demo.common;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @author guiqing.yin
 * 2024-03-28 14:50
 */
@Data
@Accessors(chain = true)
public class CommonResult<T> implements Serializable {
    private ResponseCode code;
    private String message;
    private T data;

    public CommonResult() {
    }

    public CommonResult(ResponseCode code, String message) {
        this.code = code;
        this.message = message;
    }

    public CommonResult(ResponseCode code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> CommonResult<T> success() {
        return new CommonResult<>(ResponseCode.SUCCESS, "success");
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(ResponseCode.SUCCESS, "success", data);
    }

    public static <T> CommonResult<T> error(String message) {
        return new CommonResult<>(ResponseCode.ERROR, message);
    }

    public static <T> CommonResult<T> error(ResponseCode code, String message) {
        return new CommonResult<>(code, message);
    }
}
